﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PwjCy.Lite.Common
{
    /// <summary>
    /// HashCache缓存
    /// </summary>
    public sealed class HashCacheHelper
    {
        private const string CacheKeyPrefix = "Pwjcy_Lite_HashCacheHelper";
        private System.Collections.Hashtable cacheHashTable = new System.Collections.Hashtable();
        private HashCacheHelper() { }
        private static readonly Lazy<HashCacheHelper> lazy = new Lazy<HashCacheHelper>(() => new HashCacheHelper());
        public static HashCacheHelper Instance { get { return lazy.Value; } }
        public void AddCache<T>(T obj, string key)
        {
            if (null != cacheHashTable[CacheKeyPrefix + typeof(T).FullName + key]) return;
            cacheHashTable[CacheKeyPrefix + typeof(T).FullName + key] = obj;
        }
        public T GetCache<T>(string key)
        {
            return (T)cacheHashTable[CacheKeyPrefix + typeof(T).FullName + key];
        }
    }
}
